/*******************************************************************************
 * Copyright (c) 2003 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.core.internal.api;

import java.util.Map;

import net.sourceforge.perforce.api.IError;
import net.sourceforge.perforce.api.IPerforceCommand;
import net.sourceforge.perforce.core.IClientUserListener;

import org.eclipse.core.runtime.IStatus;

/**
  * @version $Revision: 252 $
  * @author  <a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class ClientUserListenerDelegate implements IPerforceCommand 
{
	// --------------------------------------------------------------------------- Private Variables
	
	/** Stores the delegate object. */
	private final IPerforceCommand delegate;
	/** Stores the listeners. */
	private final IClientUserListener[] listeners; 
	
	// -------------------------------------------------------------------------------- Constructors
	
	/** Constructor for ClientUserListenerDelegate. */
	ClientUserListenerDelegate(IPerforceCommand theDelegate, IClientUserListener[] theListeners)
	{
		delegate = theDelegate;
		listeners = theListeners;
	}
	
	// ------------------------------------------------------------------------------ Public Methods
	
	/** @see IClientUserDelegate#finished() */
	public void finished() 
	{
		for (int i = 0; i < listeners.length; i++)
		{
			listeners[i].finished(delegate);
		}
		
		delegate.finished();
	}

	/** @see IClientUserDelegate#handleError(IError) */
	public boolean handleError(IError error) 
	{
		for (int i = 0; i < listeners.length; i++)
		{
			listeners[i].handleError(delegate, error);
		}
		
		return delegate.handleError(error);
	}

	/** @see IClientUserDelegate#inputData(IError) */
	public String inputData(IError error) 
	{
		return delegate.inputData(error);
	}

	/** @see IClientUserDelegate#message(IError) */
	public boolean message(IError error) 
	{
		return delegate.message(error);
	}

	/** @see IClientUserDelegate#outputBinary(byte[]) */
	public void outputBinary(byte[] data) 
	{
		delegate.outputBinary(data);
	}

	/** @see IClientUserDelegate#outputError(String) */
	public void outputError(String errorString) 
	{
		for (int i = 0; i < listeners.length; i++)
		{
			listeners[i].outputError(delegate, errorString);
		}
		
		delegate.outputError(errorString);
	}

	/** @see IClientUserDelegate#outputInfo(char, String) */
	public void outputInfo(char level, String infoString) 
	{
		for (int i = 0; i < listeners.length; i++)
		{
			listeners[i].outputInfo(delegate, level, infoString);
		}
		
		delegate.outputInfo(level, infoString);
	}

	/** @see IClientUserDelegate#outputStat(Map) */
	public void outputStat(Map data) 
	{
		delegate.outputStat(data);
	}

	/** @see IClientUserDelegate#outputText(byte[]) */
	public void outputText(byte[] data) 
	{
		delegate.outputText(data);
	}

	/** @see net.sourceforge.perforce.api.IPerforceCommand#getStatus() */
	public IStatus getStatus() 
	{	
		return delegate.getStatus();
	}

	/** @see net.sourceforge.perforce.api.IPerforceCommand#getCommand() */
	public String getCommand() 
	{		
		return delegate.getCommand();
	}
}
